package com.novellotus.iov.carvice.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.novellotus.iov.carvice.R;
import com.novellotus.iov.carvice.activity.AddFailureActivity;
import com.novellotus.iov.carvice.activity.AttentionActivity;
import com.novellotus.iov.carvice.activity.MapChargeStationActivity;
import com.novellotus.iov.carvice.activity.SearchCarActivity;
import com.novellotus.iov.carvice.activity.ServiceStationActivity;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Rich on 2017/12/23.
 */

public class HomePageFunctionAdapter extends RecyclerView.Adapter<HomePageFunctionAdapter.FunctionHolder> {

    private Context context;

    public HomePageFunctionAdapter(Context context) {
        this.context = context;
    }

    @Override
    public FunctionHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_function, null);
        return new FunctionHolder(view);
    }

    @Override
    public void onBindViewHolder(FunctionHolder holder, int position) {

        switch (position) {
            case 0:
                holder.img_icon.setBackgroundResource(R.mipmap.icon_attention);
                holder.tv_text.setText(context.getResources().getString(R.string.monitor));
                holder.rlt_item.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, SearchCarActivity.class);
                        intent.putExtra("type",1);
                        context.startActivity(intent);
                    }
                });
                break;
            case 1:
                holder.img_icon.setBackgroundResource(R.mipmap.icon_one_help);
                holder.tv_text.setText(context.getResources().getString(R.string.rescue));
                holder.rlt_item.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, AddFailureActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 2:
                holder.img_icon.setBackgroundResource(R.mipmap.icon_service);
                holder.tv_text.setText(context.getResources().getString(R.string.garage));
                holder.rlt_item.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, ServiceStationActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
            case 3:
                holder.img_icon.setBackgroundResource(R.mipmap.icon_charge);
                holder.tv_text.setText(context.getResources().getString(R.string.charge));
                holder.rlt_item.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        Intent intent = new Intent(context, MapChargeStationActivity.class);
                        context.startActivity(intent);
                    }
                });
                break;
        }


    }


    @Override
    public int getItemCount() {
        return 4;
    }

    class FunctionHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.img_icon)
        ImageView img_icon;
        @BindView(R.id.tv_text)
        TextView tv_text;
        @BindView(R.id.rlt_item)
        RelativeLayout rlt_item;

        FunctionHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
